﻿using System.Collections.Generic;
using System.Linq;
using XRM.Security.DataAccess.Enums;
using XRM.Security.WebUI.Security;

namespace XRM.Security.WebUI.Helpers
{
    public class Permission
    {
        public static bool AllowDepartmentEdit()
        {
            IEnumerable<string> roles = new[] {UserRoles.Administrator.ToString(), UserRoles.StructDepartmentEditor.ToString()};
            return CheckRole(roles);
        }

        public static bool AllowSkziKindView()
        {
            IEnumerable<string> roles = new[] { UserRoles.Administrator.ToString(), UserRoles.SkziKindViewer.ToString(), UserRoles.SkziKindEditor.ToString() };
            return CheckRole(roles);
        }

        public static bool AllowSkziKindEdit()
        {
            IEnumerable<string> roles = new[] { UserRoles.Administrator.ToString(), UserRoles.SkziKindEditor.ToString() };
            return CheckRole(roles);
        }

        public static bool AllowInfoSystemEdit()
        {
            IEnumerable<string> roles = new[] { UserRoles.Administrator.ToString(), UserRoles.InfoSystemEditor.ToString() };
            return CheckRole(roles);
        }

        public static bool AllowIdentityCenterEdit()
        {
            IEnumerable<string> roles = new[] { UserRoles.Administrator.ToString(), UserRoles.IdentityCenterEditor.ToString() };
            return CheckRole(roles);
        }

        public static bool AllowWorkKindEdit()
        {
            IEnumerable<string> roles = new[] { UserRoles.Administrator.ToString(), UserRoles.WorkKindEditor.ToString() };
            return CheckRole(roles);
        }

        private static bool CheckRole(IEnumerable<string> roles)
        {
            return roles.Intersect(UserPrincipal.Current.Roles).Any();
        }
    }
}